package com.ruoyi.btlfbreed.service.impl;

import java.util.List;

import com.ruoyi.btlfbreed.domain.MyTbChickenGrowData;
import com.ruoyi.btlfbreed.domain.TbChickens;
import com.ruoyi.btlfbreed.mapper.TbChickensMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.btlfbreed.mapper.TbChickenGrowthRecordsMapper;
import com.ruoyi.btlfbreed.domain.TbChickenGrowthRecords;
import com.ruoyi.btlfbreed.service.ITbChickenGrowthRecordsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 肉鸡成长记录Service业务层处理
 * 
 * @author codeman
 * @date 2024-05-07
 */
@Service
public class TbChickenGrowthRecordsServiceImpl implements ITbChickenGrowthRecordsService 
{
    @Autowired
    private TbChickenGrowthRecordsMapper tbChickenGrowthRecordsMapper;
    @Autowired
    private TbChickensMapper tbChickensMapper;

    /**
     * 查询肉鸡成长记录
     * 
     * @param recordId 肉鸡成长记录主键
     * @return 肉鸡成长记录
     */
    @Override
    public TbChickenGrowthRecords selectTbChickenGrowthRecordsByRecordId(Long recordId)
    {
        return tbChickenGrowthRecordsMapper.selectTbChickenGrowthRecordsByRecordId(recordId);
    }

    /**
     * 查询肉鸡成长记录列表
     * 
     * @param tbChickenGrowthRecords 肉鸡成长记录
     * @return 肉鸡成长记录
     */
    @Override
    public List<TbChickenGrowthRecords> selectTbChickenGrowthRecordsList(TbChickenGrowthRecords tbChickenGrowthRecords)
    {
        return tbChickenGrowthRecordsMapper.selectTbChickenGrowthRecordsList(tbChickenGrowthRecords);
    }

    /**
     * 新增肉鸡成长记录
     * 
     * @param tbChickenGrowthRecords 肉鸡成长记录
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTbChickenGrowthRecords(TbChickenGrowthRecords tbChickenGrowthRecords)
    {
        tbChickenGrowthRecords.setCreateTime(DateUtils.getNowDate());

        TbChickens tbChickens=new TbChickens();
        tbChickens.setChickenId(tbChickenGrowthRecords.getChickenId());
        tbChickens.setWeight(tbChickenGrowthRecords.getWeight().doubleValue());
        tbChickensMapper.updateTbChickens(tbChickens);

        return tbChickenGrowthRecordsMapper.insertTbChickenGrowthRecords(tbChickenGrowthRecords);
    }

    /**
     * 修改肉鸡成长记录
     * 
     * @param tbChickenGrowthRecords 肉鸡成长记录
     * @return 结果
     */
    @Override
    public int updateTbChickenGrowthRecords(TbChickenGrowthRecords tbChickenGrowthRecords)
    {
        tbChickenGrowthRecords.setUpdateTime(DateUtils.getNowDate());
        TbChickens tbChickens=new TbChickens();
        tbChickens.setChickenId(tbChickenGrowthRecords.getChickenId());
        tbChickens.setWeight(tbChickenGrowthRecords.getWeight().doubleValue());
        tbChickensMapper.updateTbChickens(tbChickens);
        return tbChickenGrowthRecordsMapper.updateTbChickenGrowthRecords(tbChickenGrowthRecords);
    }

    /**
     * 批量删除肉鸡成长记录
     * 
     * @param recordIds 需要删除的肉鸡成长记录主键
     * @return 结果
     */
    @Override
    public int deleteTbChickenGrowthRecordsByRecordIds(Long[] recordIds)
    {
        return tbChickenGrowthRecordsMapper.deleteTbChickenGrowthRecordsByRecordIds(recordIds);
    }

    /**
     * 删除肉鸡成长记录信息
     * 
     * @param recordId 肉鸡成长记录主键
     * @return 结果
     */
    @Override
    public int deleteTbChickenGrowthRecordsByRecordId(Long recordId)
    {
        return tbChickenGrowthRecordsMapper.deleteTbChickenGrowthRecordsByRecordId(recordId);
    }

    @Override
    public List<MyTbChickenGrowData> getMonthSumGrowData(String year, String chickenNo)
    {
        return tbChickenGrowthRecordsMapper.getMonthSumGrowData(year,chickenNo);
    }

    @Override
    public List<MyTbChickenGrowData> getMonthAvgGrowData(String year)
    {
        return tbChickenGrowthRecordsMapper.getMonthAvgGrowData(year);
    }
}
